package com.ray.basic;

import java.util.HashMap;
import java.util.Map;

/**
 * 静态内部类、成员内部类、局部内部类、匿名内部类
 */


public class Outer {
    private static  int radius = 1;
    private int count =2;

    //静态内部类
    static class InnerStatic {
        public void visit() {
            System.out.println("InnerStatic:" + radius);
        }
    }


    //成员内部类  定义在类内部，成员位置上的非静态类，就是成员内部类
    class Inner {
        public void visit() {
            System.out.println("Inner:" + radius);
            System.out.println("Inner:" + count);
        }
    }

    //局部内部类   定义在方法中的内部类，就是局部内部类。
    public void functionClass(){
        class FunctionInnerClass{
            public void visit() {
                System.out.println("functionClass:" + radius);
                System.out.println("functionClass:" + count);
            }
        }
        FunctionInnerClass innerClass = new FunctionInnerClass();
        innerClass.visit();
    }

    public static void main(String[] args) {
        Outer outer = new Outer();

        InnerStatic innerStatic = new Outer.InnerStatic();
        InnerStatic innerStatic2 = new InnerStatic();

        Inner inner = outer.new Inner();
        inner.visit();

        Map<A,String> map = new HashMap<A, String>();
        A a = new A();
        A n = new A();
        a.visit();
        map.put(a,"1" );
        map.put(n,"1" );
        System.out.println(map);

        outer.functionClass();

        new Thread(new Runnable() {
            public void run() {
                System.out.println("匿名内部类");
            }
        }).start();

        new Service() {
            public void method() {
                System.out.println("匿名内部类Service");
            }
        }.method();
    }
}

//匿名内部类必须继承或实现一个已有的接口
interface Service{
    void method();
}


//普通类
class A{
    public void visit() {
        System.out.println("visit outer static  variable:1111");
    }

    @Override
    public boolean equals(Object obj) {
        return true;
    }
}
